﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UPARKTaskManager
{
    public class AllTasks
    {
        public static AllTasks Instance;
        public static AllTasks GetInstance()
        {
            if (Instance == null)
            {
                Instance = new AllTasks();
            }
            return Instance;
        }

        public void GetAllTask(string allTaskPath)
        {
            string catchSVTaskPath = string.Format("{0}//CatchSVTasks", allTaskPath);
            string detectTaskPath = string.Format("{0}//DetectTasks", allTaskPath);
            string surveyTaskPath = string.Format("{0}//SurveyTasks", allTaskPath);
            AddTaskInQueue(catchSVTaskPath, CatchSVTaskQueue);
            AddTaskInQueue(detectTaskPath, DetectTaskQueue);
            AddTaskInQueue(surveyTaskPath, SurveyTaskQueue);
        }

        public void AddTaskInQueue(string path, Queue<string> taskQueue)
        {
            DirectoryInfo folder = new DirectoryInfo(path);
            FileInfo[] chldFiles = folder.GetFiles("*.zip");
            foreach (FileInfo chlFile in chldFiles)
            {
                taskQueue.Enqueue(chlFile.FullName);
            }
            DirectoryInfo[] chldFolders = folder.GetDirectories();
            foreach (DirectoryInfo chldFolder in chldFolders)
            {
                AddTaskInQueue(chldFolder.FullName, taskQueue);
            }
        }

        public Queue<string> CatchSVTaskQueue = new Queue<string>();
        public Queue<string> DetectTaskQueue = new Queue<string>();
        public Queue<string> SurveyTaskQueue = new Queue<string>();
    }
}
